/*
 * Copyright 2008. Mount Sinai Hospital, Toronto, Canada.
 * 
 * Licensed under the Apache License, Version 2.0. You
 * can find a copy of the license at:
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * IN NO EVENT SHALL MOUNT SINAI HOSPITAL BE LIABLE TO ANY PARTY FOR DIRECT, 
 * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST 
 * PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, 
 * EVEN IF MOUNT SINAI HOSPITAL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
 * DAMAGE.
 * 
 * MOUNT SINAI HOSPITAL SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND 
 * ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". 
 * MOUNT SINAI HOSPITAL HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, 
 * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 
 */

package com.sinai.mshab.data.gwt;

import com.google.gwt.user.client.ui.CheckBox;
import com.sinai.mshab.data.core.CheckBoxValueLabelPair;
import com.sinai.mshab.data.core.DataManager;

/**
 * 
 * @author Jason Kong
 * 
 */
public class CheckBoxDataManager implements
		DataManager<CheckBox, CheckBoxValueLabelPair> {

	/**
	 * Returns the current state of this CheckBox, represented by a
	 * {@link CheckBoxValueLabelPair} object. Returns null if the widget is null
	 * 
	 * @param widget
	 *            the {@code CheckBox} to get the state of.
	 * @return a {@link CheckBoxValueLabelPair} representation of the
	 *         {@link CheckBox}'s state
	 */
	public CheckBoxValueLabelPair getData(CheckBox widget) {
		// wrap the boolean in a Boolean Object
		return new CheckBoxValueLabelPair(widget.isChecked(), widget.getText());
	}

	/**
	 * Sets the selected value of {@link CheckBox} {@code widget}.
	 * 
	 * @param widget
	 *            the {@code ListBox} to get the value from.
	 * @param data
	 *            a {@link CheckBoxValueLabelPair} representation of the new
	 *            value for {@code widget}.
	 */
	public void setData(CheckBox widget, CheckBoxValueLabelPair data) {
		widget.setText(data.getLabel());
		widget.setChecked(data.isChecked());
	}

}
